//
//  MyComperesListViewController.m
//  RainbowFM
//
//  Created by Kratos on 14/12/11.
//  Copyright (c) 2014年 RB. All rights reserved.
//

#import "MyComperesListViewController.h"
#import "CompereDetailsViewController.h"

#import "ComperesListTableViewCell.h"

#import "CompereModel.h"

@interface MyComperesListViewController ()
@property (nonatomic , strong) NSMutableArray *comperesList;//主持人列表
@end

@implementation MyComperesListViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    _comperesList= [NSMutableArray array];
    
    // Do any additional setup after loading the view.
}

-(void)fetchList{
    typeof(self) self_ = self;
    [[CompereModel sharedModel]fetchComperesListWithAnchorType:AnchorTypeMy PageSize:100 currentPage:0 result:^(NSArray *compereList, NSString *msg) {
        [self_.comperesList removeAllObjects];
        [self_.comperesList addObjectsFromArray:compereList];
        [self_.tableView reloadData];
    }];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self fetchList];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - table datasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_comperesList count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ComperesListTableViewCell *cell = (ComperesListTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"ComperesListTableViewCell"];
    if (!cell) {
        NSArray * nibObjects = [[NSBundle mainBundle] loadNibNamed:@"ComperesListTableViewCell" owner:nil options:nil];
        for (id obj in nibObjects){
            if ([obj isKindOfClass:[ComperesListTableViewCell class]]){
                cell = obj;
                break;
            }
        }
        
    }
    
    CompereItem *item = _comperesList[indexPath.row];
    [cell updateContents:item];
    
    return cell;
    
}



#pragma mark - table delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    CompereItem *item = _comperesList[indexPath.row];
    NSString *title = item.anchorName;
    
    
    
    UIStoryboard *board = [UIStoryboard storyboardWithName:@"Comperes" bundle:nil];
    CompereDetailsViewController *compereDetailsViewController = [board instantiateViewControllerWithIdentifier:@"CompereDetailsViewController"];
    compereDetailsViewController.anchorid = item.anchorId;
    [compereDetailsViewController setTitle:title];
    
    [self.navigationController pushViewController:compereDetailsViewController animated:YES];
}



#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
//- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
//    
//}

//-(void)creatTestData{
//    [_comperesList removeAllObjects];
//    
//    NSArray *test = @[@{@"path":@"http://imgsrc.baidu.com/forum/w%3D580/sign=d031c1d77a899e51788e3a1c72a6d990/a3ffe0fe9925bc31b9ab13b25fdf8db1cb137034.jpg",@"name":@"陈力",@"synopsis":@"陈力：汉族，大学本科，二级播音员，重庆电视台新闻频道节目主持人。"},
//                      @{@"path":@"http://imgsrc.baidu.com/forum/w%3D580/sign=5d73733aaa18972ba33a00c2d6cd7b9d/3a858c5494eef01fb74c57ebe1fe9925bc317d4a.jpg",@"name":@"周运",@"synopsis":@"重庆电视台《重庆发现》《新闻解码》《财经时间》《信念》主持人周运"},
//                      @{@"path":@"http://hunanzhibo.com/uploads/allimg/140718/2-140GQ52G3R7.jpg",@"name":@"雷环",@"synopsis":@"雷环，也是重庆电视台著名的主持人之一，出生于海南的雷环性格上比较的活泼开朗，，盛行乐观的她将这种性格也带进了自己的主持工作中，让自己的主持工作具有了一种开朗亲切的亲和力"}];
//    for (NSDictionary *dic in test) {
//        ProgramIntroducedListModel *model = [[ProgramIntroducedListModel alloc]initWithDataDic:dic];
//        [_comperesList addObject:model];
//    }
//}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
